package com.ruoyi.lock.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lock.domain.TContract;
import com.ruoyi.lock.service.ITContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 公租房合同主Controller
 * 
 * @author arvin
 * @date 2025-03-07
 */
@RestController
@RequestMapping("/lock/contract")
public class TContractController extends BaseController
{
    @Autowired
    private ITContractService tContractService;

    /**
     * 查询公租房合同主列表
     */
    @PreAuthorize("@ss.hasPermi('lock:contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(TContract tContract)
    {
        startPage();
        List<TContract> list = tContractService.selectTContractList(tContract);
        return getDataTable(list);
    }

    /**
     * 导出公租房合同主列表
     */
    @PreAuthorize("@ss.hasPermi('lock:contract:export')")
    @Log(title = "公租房合同主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TContract tContract)
    {
        List<TContract> list = tContractService.selectTContractList(tContract);
        ExcelUtil<TContract> util = new ExcelUtil<TContract>(TContract.class);
        util.exportExcel(response, list, "公租房合同主数据");
    }

    /**
     * 获取公租房合同主详细信息
     */
    @PreAuthorize("@ss.hasPermi('lock:contract:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tContractService.selectTContractById(id));
    }

    /**
     * 新增公租房合同主
     */
    @PreAuthorize("@ss.hasPermi('lock:contract:add')")
    @Log(title = "公租房合同主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TContract tContract)
    {
        return toAjax(tContractService.insertTContract(tContract));
    }

    /**
     * 修改公租房合同主
     */
    @PreAuthorize("@ss.hasPermi('lock:contract:edit')")
    @Log(title = "公租房合同主", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TContract tContract)
    {
        return toAjax(tContractService.updateTContract(tContract));
    }

    /**
     * 删除公租房合同主
     */
    @PreAuthorize("@ss.hasPermi('lock:contract:remove')")
    @Log(title = "公租房合同主", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tContractService.deleteTContractByIds(ids));
    }
}
